package graphicstuff;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

class GUIFrame extends JFrame implements ActionListener,/*ChangeListener,*/ItemListener {
    
    //GUIPanel panel=new GUIPanel();
    //JSlider slide;
    //JToggleButton jtb;
    JTextArea jta;
    double num1;
    double num2;
    GUIFrame(){
        //jta=new JTextArea("initial\nText");
        //JLabel sliderLaber=new JLabel("cookie Print Number Slider");
        //jtb=new JToggleButton("TOGGLY TOGGLY TOO");
        //jtb.addItemListener(this);
       // slide= new JSlider(0,5,5);
       // slide.addChangeListener(this);
        JPanel Rpanel=new JPanel();
        JPanel Cpanel=new JPanel();
        
        JButton add = new JButton("+");
        JButton subtract = new JButton("-");
        JButton multiply= new JButton("*");
        JButton divide=new JButton("/");
        JButton mod=new JButton("%");
        JButton clr=new JButton("CLR");
        add.addActionListener(this);
        multiply.addActionListener(this);
        subtract.addActionListener(this);
        Rpanel.setLayout(new GridLayout(6,1));
        Cpanel.setLayout(new GridLayout(3,1));
        //FlowLayout, BotderLayout, GridLayour
        this.setLayout(new BorderLayout());
        
        Rpanel.add(mod);
        Rpanel.add(divide);
        Rpanel.add(multiply);
        Rpanel.add(subtract);
        Rpanel.add(add);
        Rpanel.add(clr);
       // Rpanel.add(slide);
        //Rpanel.add(jtb);
        //Rpanel.add(jta);
        //Rpanel.add(sliderLaber);
        //Spanel.add(exitButton);
        //Spanel.add(refresh);
        //this.add(print,BorderLayout.CENTER);
        //this.add(exitButton,BorderLayout.SOUTH);
        this.add(Rpanel,BorderLayout.EAST);
        this.add(Cpanel,BorderLayout.SOUTH);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//causes program to end when window closes
        this.setSize(500,500);//Sets the size so that it's at least visible.
        //this.pack;//makes the size match the size of the current layout
        this.setVisible(true); //Lets the user vies the JFrame.
        
    }
    @Override
    public void actionPerformed(ActionEvent ae){
        //button clicks
        if(ae.getActionCommand().equals("+"))
        {
            
            jta.setText(Double.toString(num1+num2)); 
        }
        else if(ae.getActionCommand().equals("-"))
        {
            jta.setText(Double.toString(num1-num2));
        }
        else if(ae.getActionCommand().equals("*"))
        {
            jta.setText(Double.toString(num1*num2));
        }
        else if(ae.getActionCommand().equals("/"))
        {
            jta.setText(Double.toString(num1+num2));
        }
        else if(ae.getActionCommand().equals("%"))
        {
            jta.setText(Double.toString(num1+num2));
        }
        else if(ae.getActionCommand().equals("CLR"))
        {
            jta.setText("cleared");
            num1=0.0;
            num2=0.0;
        }
       /* else if(ae.getActionCommand().equals("print"))
        {
            if(jtb.isSelected())
            {
                    for(int i=0;i<slide.getValue();i++)
            {
            jta.setText(jta.getText() +"\nCookies");
            }
            }
        }*/
        else if(ae.getActionCommand().equals("Refresh"))
        {
            System.out.println("Refreshed");
        }
    }

    //@Override
   // public void stateChanged(ChangeEvent ce) {
       // System.out.println("State Changed." + slide.getValue());
  //  }

    @Override
    public void itemStateChanged(ItemEvent ie) {
        System.out.println("");
    }
}
